<template>
    <el-container>
        <el-aside width="200px">
            <SideMenu></SideMenu>
        </el-aside>
        <el-container>
            <el-header>
                <strong>Rookie管理系统</strong>
                <div class="header-avatar">
                    <!-- 头像 -->
                    <el-avatar size="medium" :src="userInfo.avatar" style="margin-right: 5px"></el-avatar>
                    <!-- 下拉菜单 -->
                    <el-dropdown trigger="click">
						<span class="el-dropdown-link">
						  {{userInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
						</span>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item>
                                <router-link to="/userCenter">个人中心</router-link>
                            </el-dropdown-item>
                            <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </el-header>
            <el-main>
                <!--标签页-->
                <Tabs></Tabs>
                <div style="margin: 0 15px;">
                    <router-view/>
                </div>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    import SideMenu from "./inc/SideMenu";
    import Tabs from "./inc/Tabs";

    export default {
        components: {
            SideMenu,
            Tabs
        },
        data() {
            return {
                userInfo: {
                    id: "",
                    username: "",
                    avatar: ""
                }
            }
        },
        methods: {
            // 获取用户详细信息
            getUserInfo() {
                this.$axios.get("/rookie/user/userInfo").then(res => {
                    this.userInfo = res.data.result
                })
            },
            // 登出
            logout() {
                this.$axios.post("/logout").then(res => {
                    localStorage.clear();
                    sessionStorage.clear();
                    this.$store.commit("resetState");
                    this.$router.push("/login");
                })
            }
        },
        created() {
            this.getUserInfo()
        }
    }
</script>

<style scoped>
    .el-container {
        padding: 0;
        margin: 0;
        height: 100%;
    }

    .el-header {
        background-color: #17B3A3;
        color: #333;
        text-align: center;
        line-height: 60px;
    }

    .header-avatar {
        float: right;
        display: flex;
        justify-content: space-around;
        align-items: center;
        margin-right: 1%;
    }

    .el-dropdown-link {
        cursor: pointer;
    }

    a {
        text-decoration: none;
    }

    .el-main {
        padding: 0
    }
</style>